package com.example.springcode.test;

import com.example.springcode.beans.BeansException;
import com.example.springcode.beans.factory.BeanFactory;
import com.example.springcode.beans.factory.BeanFactoryAware;
import com.example.springcode.beans.factory.DisposableBean;
import com.example.springcode.beans.factory.InitializingBean;
import lombok.Data;

/**
 * @Author: chenxiuxiang
 * @Date: 2024-03-04 18:24
 * @Description:
 */
@Data
public class UserService implements InitializingBean, BeanFactoryAware, DisposableBean {
    private String id;
    private String company;
    private String location;

    private IUserDao userDao;

    private BeanFactory beanFactory;

    public void queryUserInfo() {
        try {
            System.out.println("查询用户: " + id + " 信息:" + userDao.queryUserName(id));
            System.out.println(company);
            System.out.println(location);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("执行UserService销毁方法");
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("执行UserService初始化方法");
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }
}
